﻿using System.Globalization;

namespace T4UtilityBelt.UxDesigns.Styles
{
    public class FontFamily
    {
        private readonly string _familyName;

        public FontFamily(string familyName)
        {
            _familyName = familyName;
        }

        public string Source
        {
            get { return _familyName; }
        }

        public override bool Equals(object obj)
        {
            var fontFamily = obj as FontFamily;
            if (fontFamily != null)
            {
                if (_familyName == null)
                {
                    return Equals(obj);
                }
                string lower = _familyName.ToLower(CultureInfo.CurrentCulture);
                string source = fontFamily.Source;
                if (fontFamily.Source != null)
                {
                    source = fontFamily.Source.ToLower(CultureInfo.CurrentCulture);
                }
                return lower.Equals(source);
            }
            return false;
        }

        public override int GetHashCode()
        {
            if (_familyName == null)
            {
                return GetHashCode();
            }
            string lower = _familyName.ToLower(CultureInfo.CurrentCulture);
            return lower.GetHashCode();
        }

        public override string ToString()
        {
            if (_familyName != null)
            {
                return _familyName;
            }
            return string.Empty;
        }
    }
}